package com.songshuai.webapi.jobapi.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum GradeOldMap {
    One(1004001, "one"),
    Two(1004002, "two"),
    Three(1004003, "three"),
    Four(1004004, "four"),
    Five(1004005, "five"),
    Six(1004006, "six"),
    SixMiddle(1004007, "six"),
    Seven(1004008, "seven"),
    Eight(1004009, "eight"),
    Nine(10040010, "nine"),
    HighOne(10040011, "other"),
    HighTwo(10040012, "other"),
    HighThree(10040013, "other"),
    HighFour(10040014, "other"),
    Other(1004100, "other");
    private int code;
    private String msg;

    GradeOldMap(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return GradeOldMap.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return GradeOldMap.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(GradeOldMap err : GradeOldMap.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getErrorCode(){
        return code;
    }

    public String getErrorMsg(){
        return msg;
    }
}
